package logic

import (
	"context"
	"goodsrpc/mysql"

	"goodsrpc/goods"
	"goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *goods.UserListRequest) (*goods.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var u mysql.User
	list, err := u.UserList(int(in.State))
	if err != nil {
		return nil, err
	}
	var UserList []*goods.UserList
	for _, user := range list {
		List := goods.UserList{
			Mobile: user.Mobile,
			Img:    user.Img,
			State:  user.State,
		}
		UserList = append(UserList, &List)
	}

	return &goods.UserListResponse{
		List: UserList,
	}, nil
}
